import answers from '../../apis/answers';

export default {
  namespaced: true,
  state: {
    loading: false,
    answers: [],
    count: 0,
  },
  mutations: {
    setLoading(state, data) {
      state.loading = data;
    },
    setAnswers(state, data) {
      state.answers = data;
    },
    setCount(state, data) {
      state.count = data;
    },
  },
  actions: {
    async getAnswers({ commit }, data) {
      commit('setLoading', true);
      const { data: { result, count } } = await answers.getAnswers(data);
      commit('setAnswers', result);
      commit('setCount', count);
      commit('setLoading', false);
    },
  },
};
